package com.guoxin.chapter8;

/**
 * 方法静态分派演示
 *
 * @author guoxin
 * @date 2019/9/25
 */
public class StaticDispatch {
    static abstract class Human {
    }

    static class Man extends Human {
    }

    static class Women extends Human {
    }

    public void sayHello(Human guy) {
        System.out.println("hello,guy!");
    }

    public void sayHello(Man guy) {
        System.out.println("hello,gentleman!");
    }

    public void sayHello(Women guy) {
        System.out.println("hello,lady!");
    }

    public static void main(String[] args) {
        // 实际类型变化
        Human man = new Man();
        Human women = new Women();
        StaticDispatch sr = new StaticDispatch();
        // 静态类型变化
        sr.sayHello((Man) man);
        sr.sayHello((Women) women);
    }
}
